package com.shadow.mall.pay.remote.dubbo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;

import com.shadow.mall.common.core.JsonResult;
import com.shadow.mall.order.api.AfterSaleApi;
import com.shadow.mall.order.domain.request.RefundCallbackRequest;
import com.shadow.mall.pay.exception.PayBizException;
import com.shadow.mall.pay.remote.fallback.AfterSaleRemoteFallback;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单售后远程接口
 *
 *
 * @version 1.0
 */
//@Component
public class AfterSaleRemote {

    @Autowired
    private AfterSaleApi afterSaleApi;

    /**
     * 取消订单支付退款回调
     */
    @SentinelResource(value = "AfterSaleRemote:refundCallback", fallbackClass = AfterSaleRemoteFallback.class, fallback = "refundCallbackFallback")
    public JsonResult<Boolean> refundCallback(RefundCallbackRequest payRefundCallbackRequest) {
        JsonResult<Boolean> jsonResult = afterSaleApi.refundCallback(payRefundCallbackRequest);
        if (!jsonResult.getSuccess()) {
            throw new PayBizException(jsonResult.getErrorCode(), jsonResult.getErrorMessage());
        }
        return jsonResult;
    }

}
